

//
//  CATransitionViewController.m
//  界面动画集
//
//  Created by YYY on 2017/7/3.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

#import "CATransitionViewController.h"

@interface CATransitionViewController ()
@property(nonatomic,strong)UIImageView *pearImageView;
@property(nonatomic,assign)NSInteger flag;

@end

@implementation CATransitionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"CATransition";
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"转场动画" style:UIBarButtonItemStylePlain target:self action:@selector(transitionAnimation)];
    [self.view addSubview:self.pearImageView];
    // Do any additional setup after loading the view.
}

-(void)transitionAnimation
{
    if (_flag == 0)
    {
        //立方动画
        CATransition *transition = [CATransition animation];
        //私有动画类型的值有："cube"、"suckEffect"、"oglFlip"、 "rippleEffect"、"pageCurl"、"pageUnCurl"等等。
        transition.type = @"cube";
        
        transition.subtype = kCATransitionFromTop;
        transition.duration = 2.0f;
        [self.pearImageView.layer addAnimation:transition forKey:nil];
    }
    else if (_flag == 1)
    {
        //动画
        CATransition *transition = [CATransition animation];
        transition.type = @"suckEffect";
        
        transition.subtype = kCATransitionFromTop;
        transition.duration = 2.0f;
        [self.pearImageView.layer addAnimation:transition forKey:nil];
    }
    else if (_flag == 2)
    {
        //动画
        CATransition *transition = [CATransition animation];
        transition.type = @"oglFlip";
        
        transition.subtype = kCATransitionFromTop;
        transition.duration = 2.0f;
        [self.pearImageView.layer addAnimation:transition forKey:nil];
    }
    else if (_flag == 3)
    {
        //波纹动画
        CATransition *transition = [CATransition animation];
        transition.type = @"rippleEffect";
        
        transition.subtype = kCATransitionFromTop;
        transition.duration = 2.0f;
        [self.pearImageView.layer addAnimation:transition forKey:nil];
    }
    else if (_flag == 4)
    {
        //书页反转动画
        CATransition *transition = [CATransition animation];
        transition.type = @"pageCurl";
        
        transition.subtype = kCATransitionFromTop;
        transition.duration = 2.0f;
        [self.pearImageView.layer addAnimation:transition forKey:nil];
    }
    else if (_flag == 5)
    {
        //书页合拢动画
        CATransition *transition = [CATransition animation];
        transition.type = @"pageUnCurl";
        
        transition.subtype = kCATransitionFromTop;
        transition.duration = 2.0f;
        [self.pearImageView.layer addAnimation:transition forKey:nil];
    }
    _flag ++;
}

-(UIImageView *)pearImageView
{
    if (!_pearImageView)
    {
        _pearImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pear"]];
        //_pearImageView.center = self.view.center;
        _pearImageView.frame = CGRectMake(50, 200, 100, 100);
    }
    return  _pearImageView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
